package com.jiuzhou.guanwang.jzcp.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jiuzhou.guanwang.jzcp.R;
import com.jiuzhou.guanwang.jzcp.bean.ExpDetailResult.DataBean.ArticlePagingBean.ItemListBean;
import com.jiuzhou.guanwang.jzcp.utils.CommonUtils;

import java.util.List;

public class ExpMatchAdapter extends BaseAdapter {
    private Context mContext;
    private List<ItemListBean> mData;

    class ViewHolder {
        TextView timeTv;
        TextView titleTv;

        ViewHolder() {
        }
    }

    public ExpMatchAdapter(Context context) {
        this.mContext = context;
    }

    public int getCount() {
        return CommonUtils.isEmpty(this.mData) ? 0 : this.mData.size();
    }

    public Object getItem(int position) {
        return CommonUtils.isEmpty(this.mData) ? null : (ItemListBean) this.mData.get(position);
    }

    public long getItemId(int position) {
        return (long) position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(this.mContext).inflate(R.layout.item_exp_detail, parent, false);
            holder.titleTv = (TextView) convertView.findViewById(R.id.tv_title);
            holder.timeTv = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ItemListBean itemListBean = (ItemListBean) this.mData.get(position);
        if (itemListBean != null) {
            if (!TextUtils.isEmpty(itemListBean.title)) {
                holder.titleTv.setText(itemListBean.title);
            }
            if (!TextUtils.isEmpty(itemListBean.match_time)) {
                holder.timeTv.setText(itemListBean.match_time);
            }
        }
        return convertView;
    }

    public void setData(List<ItemListBean> data) {
        this.mData = data;
        notifyDataSetChanged();
    }
}